<template>
    <div class="login">
        <logo></logo>
        <div class="form_box">
            <p>登录</p>
            <mt-field
                label="用户名"
                placeholder="请输入用户名"
                v-model="lname"
            ></mt-field>
            <mt-field
                label="密码"
                placeholder="请输入密码"
                type="password"
                v-model="lpassword"
            ></mt-field>
            <mt-button type="primary" size="large" @click="denglu"
                >登录</mt-button
            >
        </div>
    </div>
</template>

<script>
import logo from "../components/logo";
import { Toast } from "mint-ui";
export default {
    name: "login",
    components: {
        logo
    },
    data: function() {
        return {
            lname: "",
            lpassword: ""
        };
    },
    mounted() {
        this.checkturn();
    },
    methods: {
        denglu() {
            if (this.lname == "" || this.lpassword == "") {
                return Toast({
                    message: "请填写登录信息",
                    position: "center",
                    duration: 2000
                });
            }
            this.axios({
                method: "post",
                url:
                    this.common.baseURL +
                    "/login?username=" +
                    this.lname +
                    "&password=" +
                    this.lpassword,
                // url: '/login',
                // url:'http://localhost:8001/apis/login',
                data: this.qs.stringify({
                    username: this.lname,
                    password: this.lpassword
                }),
                withCredentials: true
            })
                .then(response => {
                    if (response.data.code == 0) {
                        localStorage.wjwdata = JSON.stringify(response.data);
                        this.$router.push({
                            path: "/index",
                            query: { selected: "2" }
                        });
                    } else {
                        Toast({
                            message: response.data.message,
                            position: "center",
                            duration: 2000
                        });
                    }
                })
                .catch(error => {
                    console.log(error);
                });
        },
        checkturn() {
            this.axios({
                method: "get",
                url:
                    this.common.baseURL +
                    "/wxpulic/listRegistCustom?pageNum=0&pageSize=10",
                data: {
                    pageNum: 0,
                    pageSize: 10
                },
                withCredentials: true
            }).then(response => {
                console.log(response);
                if (response.data.code != -8) {
                    this.$router.push({
                        path: "/index",
                        query: { selected: "2" }
                    });
                }
            });
        }
    }
};
</script>

<style scoped lang="less">
.login {
    overflow: hidden;
    width: 100%;

    .form_box {
        overflow: hidden;
        width: 5.2rem;
        padding: 0.6rem;
        height: 6.6rem;
        background: white;
        margin: -1.8rem 0.55rem 0.1rem 0.55rem;
        box-shadow: 0px 0px 10px #e0d8d8;
        border-radius: 0.12rem;

        p {
            font-size: 0.4rem;
            text-align: center;
            margin: 0.2rem 0 0.7rem 0;
            color: #159dfd;
            font-weight: bold;
            letter-spacing: 2px;
        }

        .mint-cell {
            margin-top: 0.2rem;
            .mint-cell-title {
                width: 70px;
            }
        }
        button {
            margin-top: 1rem;
        }
    }
}
</style>
